//
//  CityViewController.m
//  UI09_homework(省市区)
//
//  Created by Hanlingyu on 16/7/26.
//  Copyright © 2016年 ltq. All rights reserved.
//

#import "CityViewController.h"
#import "Zone.h"
#import "City.h"
#import "ZoneViewController.h"
#define kTableViewReuse @"reuse"
@interface CityViewController ()
<
    UITableViewDataSource,
    UITableViewDelegate
>
@property (nonatomic, strong) UITableView *cityTableView;

@end

@implementation CityViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    self.navigationItem.title = _province.name;
    
    self.cityTableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    _cityTableView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_cityTableView];
    
    _cityTableView.dataSource = self;
    _cityTableView.delegate = self;

    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return _province.array.count;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kTableViewReuse];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:kTableViewReuse];
    }
    City *city = _province.array[indexPath.row];
    cell.textLabel.text = city.name;
    cell.detailTextLabel.text = city.number;
    return cell;
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    ZoneViewController *zoneVC = [[ZoneViewController alloc] init];
    [self.navigationController pushViewController:zoneVC animated:YES];
    City *city = _province.array[indexPath.row];
    zoneVC.city = city;
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
